// 表单的状态
var stat = true;

//经度 longitude  纬度 latitude
var longitude = 0; //经度
var latitude = 0;  //纬度
var totalvalue = 0; //总价



function fun1(){
	//需要 正则 的数据  两个联系方式   重量
	var send = /^(\d{6,6}|\d{11,11})$/; //联系电话
	var	sendercontactway = $("#sendercontactway").val(); //寄件人联系方式 ？
	if(send.test(sendercontactway)){
		$("#div1").html("<p style='color: #0000FF;padding-top: 15px;padding-left: 10px;'>OK</p>");
		stat = true;
	}else{
		$("#div1").html("<p style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>错误</p>");
		stat = false;
	}
	if(sendercontactway == ""){
		$("#div1").html("<p style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>必填项</p>");
		stat = false;
	}
}

function fun2(){
	var zong = /^\d{1,5}$/;
	var weight = $("#weight").val(); //重量
	if(zong.test(weight)){
		$("#div2").html("<p style='color: #0000FF;padding-top: 15px;padding-left: 10px;'>OK</p>");
		if(weight>2){
			totalvalue = weight-2;
			totalvalue = totalvalue * 5 + 8;
			$("#zhongjia").html("<span style='color: #FF0000;'>"+totalvalue+"&nbsp;元</span>");
		}else{
			$("#zhongjia").html("<span style='color: #FF0000;'>"+8+"&nbsp;元</span>");
		}
		stat = true;
	}else{
		$("#div2").html("<p style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>错误</p>");
		$("#zhongjia").html("<span style='color: #FF0000;'>"+0+"&nbsp;元</span>");
		stat = false;
	}
	if(weight == ""){
		$("#div2").html("<p style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>必填项</p>");
		$("#zhongjia").html("<span style='color: #FF0000;'>"+0+"&nbsp;元</span>");
		stat = false;
	}
	
}

function fun3(){
	var send = /^(\d{6,6}|\d{11,11})$/; //联系电话
	var	concontactway  = $("#concontactway").val(); //收件人联系方式 ？
	if(send.test(concontactway)){
		$("#div3").html("<p style='color: #0000FF;padding-top: 15px;padding-left: 10px;'>OK</p>");
		stat = true;
	}else{
		$("#div3").html("<p style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>错误</p>");
		stat = false;
	}
	
	if(concontactway == ""){
		$("#div3").html("<p style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>必填项</p>");
		stat = false;
	}
}


function fun4(){
	var senderinformation = $("#senderinformation").val();
	var  senderinf = /^([\u2E80-\u9FFF a-zA-Z]{2,7})$/;
	if(senderinf.test(senderinformation)){
		$("#div4").html("<span style='color: #0000FF;padding-top: 15px;padding-left: 10px;'>OK</span>");
		stat = true;
	}else{
		$("#div4").html("<span style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>错误</span>");
		stat = false;
	}
	if(senderinformation==""){
		$("#div4").html("<span style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>必填项</span>");
		stat = false;
	}
}

function fun5(){
	var consigneeinformation = $("#consigneeinformation").val();
	var senderinf = /^([\u2E80-\u9FFF a-zA-Z]{2,7})$/;
	if(senderinf.test(consigneeinformation)){
		$("#div5").html("<span style='color: #0000FF;padding-top: 15px;padding-left: 10px;'>OK</span>");
		stat = true;
	}else{
		$("#div5").html("<span style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>错误</span>");
		stat = false;
	}
	if(consigneeinformation==""){
		$("#div5").html("<span style='color: #FF0000;padding-top: 15px;padding-left: 10px;'>必填项</span>");
		stat = false;
	}
	
	
}






var map = new BMap.Map("container");
map.centerAndZoom("宁波", 12);
map.enableScrollWheelZoom(); //启用滚轮放大缩小，默认禁用
map.enableContinuousZoom(); //启用地图惯性拖拽，默认禁用

map.addControl(new BMap.NavigationControl()); //添加默认缩放平移控件
map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
map.addControl(new BMap.OverviewMapControl({
	isOpen: true,
	anchor: BMAP_ANCHOR_BOTTOM_RIGHT
})); //右下角，打开

var localSearch = new BMap.LocalSearch(map);
localSearch.enableAutoViewport(); //允许自动调节窗体大小
function searchByStationName() {
	
	map.clearOverlays(); //清空原来的标注
	var keyword = document.getElementById("placeofdeparture").value;
	localSearch.setSearchCompleteCallback(function(searchResult) {
		var poi = searchResult.getPoi(0);
		longitude = poi.point.lng;  //经度
		latitude = poi.point.lat  //纬度
		
		map.centerAndZoom(poi.point, 13);
		var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat)); // 创建标注，为要查询的地方对应的经纬度
		map.addOverlay(marker);
		var content = document.getElementById("placeofdeparture").value + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat;
		var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
		marker.addEventListener("click", function() {
			this.openInfoWindow(infoWindow);
		});
		// marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	});
	localSearch.search(keyword);
}


var ac = new BMap.Autocomplete( //建立一个自动完成的对象
	{
		"input": "placeofdeparture",
		"location": map
	});
ac.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
	var str = "";
	var _value = e.fromitem.value;
	var value = "";
	if(e.fromitem.index > -1) {
		value = _value.province + _value.city + _value.district + _value.street + _value.business;
	}
	str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

	value = "";
	if(e.toitem.index > -1) {
		_value = e.toitem.value;
		value = _value.province + _value.city + _value.district + _value.street + _value.business;
	}
	str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
	G("searchResultPanel").innerHTML = str;
});

var myValue;
ac.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
	var _value = e.item.value;
	myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
	G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
	setPlace();
});

var ac1 = new BMap.Autocomplete( //建立一个自动完成的对象
	{
		"input": "cargoinformation",
		"location": map
	});
ac1.addEventListener("onhighlight", function(e) { //鼠标放在下拉列表上的事件
	var str = "";
	var _value = e.fromitem.value;
	var value = "";
	if(e.fromitem.index > -1) {
		value = _value.province + _value.city + _value.district + _value.street + _value.business;
	}
	str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

	value = "";
	if(e.toitem.index > -1) {
		_value = e.toitem.value;
		value = _value.province + _value.city + _value.district + _value.street + _value.business;
	}
	str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
	G("searchResultPanel").innerHTML = str;
});

ac1.addEventListener("onconfirm", function(e) { //鼠标点击下拉列表后的事件
	var _value = e.item.value;
	myValue = _value.province + _value.city + _value.district + _value.street + _value.business;
	G("searchResultPanel").innerHTML = "onconfirm<br />index = " + e.item.index + "<br />myValue = " + myValue;
	setPlace();
});